package com.nkzy.mapper;

import com.nkzy.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //在Mapper中的方法都是抽象的
    //1.插入数据，对数据库表的增、删除、改方法，可以有返回值，也可以没有返回值
    @Insert("insert into user(username,password,create_time,update_time) values(#{username},#{password},now(),now())")
    int insert(String username,String password);
    @Insert("insert into user(username,password,create_time,update_time) values(#{username},#{password},now(),now())")
    void insert02(String username,String password);
    //2.查询一个
    @Select("select * from user where username=#{username}")
    User selectUserByName(String username);
    //根据id查找一个用户
    @Select("select * from user where id=#{id}")
    User selectUserById(Integer id);
    //3.查询多个
    @Select("select * from user")
    List<User> selectAll();
    //4.修改
    @Update("update user set username=#{username},email=#{email},nickname=#{nickname},update_time=#{updateTime} where id=#{id}")
    void update(User user);
    //5，删除
    @Delete("delete from user where id=#{id}")
    void delete(Integer id);
    @Update("update user set user_pic=#{avatarUrl},update_time=now() where id=#{id}")
    void updateAvatar(String avatarUrl, Integer id);
    @Update("update user set password=#{newPwd},update_time=now() where id=#{id}")
    void updatePwd(String newPwd, Integer id);
}
